<!-- yunqi002 于 2020/11/27 16:28 创建addCrashType.vue 文件 -->
<template>
  <div class="app-container">
    <el-form ref="form" :model="form" :label-width="formLabelWidth">
      <el-row>
        <el-col :span="12">
          <el-form-item label="异常类型名称">
            <el-input v-model="form.name" placeholder="请输入异常类型名称" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="状态">
            <template>
              <el-select v-model="form.deleted" placeholder="请选择">
                <el-option
                  v-for="item in status"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </template>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="附加参数">
            <el-input v-model="form.des" type="textarea" placeholder="请输入附加参数" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item class="icenter">
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button @click="closeFun">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveCrashType } from '@/api/CrashHandlerApi'
export default {
  name: 'AddCrashType',
  props: {},
  data() {
    return {
      formLabelWidth: '100px',
      status: [{
        value: '0',
        label: '开启'
      }, {
        value: '1',
        label: '禁用'
      }],
      form: {
        deleted: '0',
        name: '',
        des: ''
      }
    }
  },
  watch: {},
  created() {
    this.initData()
  },
  methods: {
    initData() {
      // var ts = this
    },
    onSubmit() {
      var ts = this
      console.error('提交', this.form)
      // saveCrashType(JSON.stringify(this.form)).then(res => {
      saveCrashType(this.form).then(res => {
        var data = res.data
        if (data.code === '000000') {
          ts.$message.success(data.msg)
          setTimeout(function() {
            ts.closeFun()
          }, 1500)
        } else {
          ts.$message.error(data.msg)
        }
      }).catch(error => {
        console.error('error', error)
        ts.$message.error(error)
      })
    },
    closeFun() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped>

</style>
